<template>
	<view class="home">
		<swiper indicator-dots circular>
			<swiper-item v-for="item in swipers" :key="item.id">
				<image :src="item.img"></image>
			</swiper-item>
		</swiper>
		<view class="nav" v-show="isdemo">
			<view class="navItem" v-for="(item,index) in navs" :key="index" @click="navItemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
		</view>
		
		<!-- <u-notice-bar :text="articleTitle" direction="column" ></u-notice-bar> -->

		<!--推荐内容-->
		<view class="redCase">
			<view class="tit u-p-30" @click="getData">推荐商品</view>
			<goods-list @goodsItemClick="goGoodsDetail" :goods='goods'></goods-list>
		</view>

		<!--推荐内容
		<view class="redCase">
			<view class="tit">最新文章</view>
			<news-list @itemClick="goNewsDetail" :news="news"></news-list>
		</view>-->

	</view>
</template>

<script>
	import {
		getHome
	} from '@/api/api.js'
	import caseList from '../../components/goods-list/goods-list.vue'
	import newsList from '../../components/news-list/news-list.vue'
	export default {
		data() {
			return {
				isdemo: false,
				swipers: [],
				goods: [],
				news: [],
				navs: [],
				flags: false,
				is_show: false,
				bgnum: 7,
				is_error: false,
				is_fiber: false,
				articleTitle: [],
				articleUrl: []
				
			}
		},
		onLoad() {
			this.getData()
		},
		components: {
			'goods-list': caseList,
			'news-list': newsList
		},
		methods: {

			goGoodsDetail(id) {
				console.log(id);
				uni.navigateTo({
					url: '/pages/goods-detail/goods-detail?id=' + id
				})
			},
			async getData() {

				await getHome().then((res) => {
					console.log(res)
					this.news = res.news
					this.swipers = res.swipers
					this.goods = res.goods
					let arr = [];
					this.news.forEach(function (item) {
						console.log(item.title);
						arr.push(item.title);
					});
					this.articleTitle = arr;
					console.log(arr);
				}).catch(() => {

				})
			},
			navItemClick(url) {
				console.log(url)
				uni.navigateTo({
					url
				})
			},
			goNewsDetail(id) {
				uni.navigateTo({
					url: '/pages/news-detail/news-detail?id=' + id
				})
			}
		}
	}
</script>

<style lang="scss">
	.home {
		swiper {
			width: 750rpx;
			height: 380rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}
	}

	.nav {
		display: flex;
		margin: 10rpx 0;

		.navItem {
			width: 20%;
			text-align: center;

			view {
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				background-color: #8f8f94;
				font-size: 50rpx;
				color: #fff;
				line-height: 100rpx;
				margin: 10rpx auto;
			}

			text {
				font-size: 30rpx;
			}
		}

	}

	.redCase {
		background-color: #eee;
		overflow: hidden;
		position: relative;
		

		.tit {
			font-size: 32rpx;
			color: #000;
			text-align: left;
			letter-spacing: 1px;
			// background-color: #fff;
			margin: 5rpx 0;
			padding-top: 22rpx;
			font-weight: 700;
			margin:6rpx 24rpx ;
		}

	}
	.device{
		height: 50px;
		width: 50px;;
		background-color: aqua;
		position: absolute;
	}
</style>
